#include <fstream>
#include <iomanip>
#include<cstdlib>
#include<cmath>
using namespace std;
const int iParticle=20000;
const double clight=2.9979e8;
const double dFreq=324e6;
const double dBeta=0.47;
double pi=3.14159;
void RandBall(double rn)
{
  ofstream of("beam.txt");
  srand( (unsigned)time( NULL ) );   
  of<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<130.0<<endl;
  srand( (unsigned)time( NULL ) );
  double dx,dy,dz;
  //====================================================
  /*
  double dPhi1,dPhi2,r;
  for(int i=0;i<iParticle;i++)
  {
    r=rn*(double(rand()%1000)/1000);
    dPhi1=pi*(double(rand()%1000)/1000.0);
    dPhi2=2*pi*(double(rand()%1000)/1000.0);
    dx=r*sin(dPhi1)*cos(dPhi2);
    dy=r*sin(dPhi1)*sin(dPhi2);
    dz=r*cos(dPhi1);
      dz=dz*2*pi/dBeta/clight*dFreq;
      of<<dx<<" "<<0<<" "<<dy<<" "<<0<<" "<<dz<<" "<<130<<endl;
  }
  */
  //=======================================
  for(int i=0;i<iParticle;)
  {
    dx=rn*(double(rand()%2000)/1000.0-1.0);
    dy=rn*(double(rand()%2000)/1000.0-1.0);
    dz=rn*(double(rand()%2000)/1000.0-1.0);
    if(sqrt(dx*dx+dy*dy+dz*dz)<=rn*(1+1.0e-4))
    {
      dz=dz*2*pi/dBeta/clight*dFreq;
      of<<dx<<" "<<0<<" "<<dy<<" "<<0<<" "<<dz<<" "<<130<<endl;
      i++;
    }
  }
  //===========================================
  of.close();
}
void RandSurface(double rn)
{
  ofstream of("beam.txt");
  srand( (unsigned)time( NULL ) );   
  of<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<130.0<<endl;
  srand( (unsigned)time( NULL ) );
  double dx,dy,dz;
  for(int i=0;i<iParticle;)
  {
    dx=rn*(double(rand()%2000)/1000.0-1.0);
    dy=rn*(double(rand()%2000)/1000.0-1.0);
    dz=rn*(double(rand()%2000)/1000.0-1.0);
    if(sqrt(dx*dx+dy*dy+dz*dz)<=rn*(1+1e-2)&&sqrt(dx*dx+dy*dy+dz*dz)>=rn*(1-1e-2))
    {
      dz=dz*2*pi/dBeta/clight*dFreq;
      of<<dx<<" "<<0<<" "<<dy<<" "<<0<<" "<<dz<<" "<<130<<endl;
      i++;
    }
  }
  of.close();
}
void RandCylinder(double rn,double Height)
{
  ofstream of("beam.txt");
  srand( (unsigned)time( NULL ) );   
  of<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<130.0<<endl;
  srand( (unsigned)time( NULL ) );
  double dx,dy,dz;
  for(int i=0;i<iParticle;)
  {
    dx=rn*(double(rand()%2000)/1000.0-1.0);
    dy=rn*(double(rand()%2000)/1000.0-1.0);
    if(sqrt(dx*dx+dy*dy)<=rn)
    {
    dz=rn*(double(rand()%2000)/1000.0-1.0);
      dz=dz*2*pi/dBeta/clight*dFreq;
      of<<dx<<" "<<0<<" "<<dy<<" "<<0<<" "<<dz<<" "<<130<<endl;
      i++;
    }
  }
  of.close();
  }

